package connect4client.commands;

import messages.PlayerMoveMessage;
import connect4client.user.User;

/**
 * The PlayerMove command.
 * 
 * This command will handle PlayerMove messages.
 */
public class PlayerMoveCommand extends Command {

	public PlayerMoveCommand(PlayerMoveMessage inviteMessage) {
		super(inviteMessage);
	}


	@Override
	public void execute() {
		PlayerMoveMessage message = ((PlayerMoveMessage) this.message);

		String nextPlayer = message.getNextPlayerLogin();
		User me = controller.getUser();

		// The match is Over. There is no next player
		if (nextPlayer == null) {
			nextPlayer = message.getPlayerLogin();
			if (nextPlayer.equals(me.getLogin()))
				nextPlayer = "";
			else
				nextPlayer = me.getLogin();
		}

		guiMediator.playerMove(message.getMove(), message.getMatchId(), nextPlayer);
	}
}
